/**
 * 
 */
package cn.springsoter.core.log4j2;

import javax.annotation.PostConstruct;

import org.slf4j.MDC;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import cn.springsoter.core.launch.utils.INetUtil;

/**
 * @author kevin
 *
 */
@Component
public class LogParamMDC implements EnvironmentAware {

	private static Environment environment;

	@Override
	public void setEnvironment(Environment environment) {
		LogParamMDC.environment = environment;
	}

	@PostConstruct
	public void initMDC() {
		putMDC();
	}
	
	public static void putMDC() {
		String appName = environment.getProperty("spring.application.name");
		MDC.put("applicationName", appName);
		MDC.put("hostName", INetUtil.getHostName());
		MDC.put("ip", INetUtil.getHostIp());
	}
}
